package pseudoAssemblerCompiler.twopassassembler.view.util;

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.ToolItem;

import java.util.ArrayList;
import java.util.List;

/**
 * User: Роман
 * Date: 22.05.12
 * Time: 10:32
 */
public class ToolBarContainer {

    /**
     * Панель инструментов
     */
    private ToolBar _toolBar;

    private List<ToolItem> _toolItems = new ArrayList<ToolItem>();

    public ToolBar getToolBar() {
        return _toolBar;
    }

    public ToolBarContainer(Composite parent) {
        _toolBar = new ToolBar(parent, SWT.HORIZONTAL);
        layouts();
    }

    public ToolItem createToolItem(String aToolItemName) {
        ToolItem toolItem = new ToolItem(getToolBar(), SWT.PUSH);
        toolItem.setText(aToolItemName);
        _toolItems.add(toolItem);
        return toolItem;
    }

    public ToolItem createToolItem(String aToolItemName, Image aImage) {
        ToolItem toolItem = createToolItem(aToolItemName);
        toolItem.setImage(aImage);
        return toolItem;
    }

    private void layouts() {
        FormData formData;

        //Панели инструментов
        formData = new FormData();
        formData.left = new FormAttachment(0, 0);
        formData.top = new FormAttachment(0, 0);
        formData.right = new FormAttachment(100, 0);
        formData.bottom = new FormAttachment(100, 0);
        _toolBar.setLayoutData(formData);
    }
}
